using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace Sedna.Security
{
    public class RSASigner
    {
        private RSACryptoServiceProvider signer;
        private byte[] publicKey;

        public RSASigner()
        {
            signer = new RSACryptoServiceProvider();
            publicKey = signer.ExportCspBlob(false);
        }

        public RSASigner(int keyLength)
        {
            signer = new RSACryptoServiceProvider();
            signer.KeySize = keyLength;
            publicKey = signer.ExportCspBlob(false);
        }

        public byte[] ExportKeyPair()
        {
            return signer.ExportCspBlob(true);
        }

        public void SetKey(byte[] data)
        {
            signer.ImportCspBlob(data);
        }

        public byte[] Sign(byte[] data)
        {
            return signer.SignData(data, new SHA1CryptoServiceProvider());
        }

        public bool Verify(byte[] data, byte[] sign)
        {
            return signer.VerifyData(data, new SHA1CryptoServiceProvider(), sign);
        }        
    }
}
